package ar.edu.unq.wannaplay.persistence.daos;

import org.joda.time.Interval;

import ar.edu.unq.wannaplay.employee.Employee;
import ar.edu.unq.wannaplay.exceptions.EmployeeCantTakeLicenceException;
import ar.edu.unq.wannaplay.exceptions.NegativeNumberException;
import ar.edu.unq.wannaplay.helpers.LicenceSpitter;
import ar.edu.unq.wannaplay.persistence.genericdaos.HibernateGenericDao;

public class LicenceSpitterDAO extends HibernateGenericDao<LicenceSpitter> {

    private static final long serialVersionUID = 1L;

    private EmployeeDAO employeeDAO;

    @Override
    protected Class<LicenceSpitter> getDomainClass() {
        return LicenceSpitter.class;
    }

    public LicenceSpitter getUnique() {
        return this.findAll().get(0);
    }

    public void giveLicenceToEmployee(final String licenceName, final Employee employee, final Interval licenceInterval)
            throws EmployeeCantTakeLicenceException {
        LicenceSpitter licenceSpitter = this.getUnique();
        licenceSpitter.giveLicenceTo(licenceName, employee, licenceInterval);
        employeeDAO.update(employee);
    }

    public void addLicenceType(final String newLicence, final int anualMax, final int consecutiveMax)
            throws NegativeNumberException {
        LicenceSpitter licenceSpitter = this.getUnique();
        licenceSpitter.addLicence(newLicence, anualMax, consecutiveMax);
        this.update(licenceSpitter);
    }

    public EmployeeDAO getEmployeeDAO() {
        return employeeDAO;
    }

    public void setEmployeeDAO(final EmployeeDAO employeeDAO) {
        this.employeeDAO = employeeDAO;
    }
}
